﻿namespace SLClient.CustomerControls
{
    using SLClient.Extension;
    using SLClient.Infrastructure;
    using SLClient.ServiceAPI;
    using System;
    using System.Collections.ObjectModel;
    using System.Runtime.CompilerServices;

    public class LastOpenDataControlViewModel : ViewModelBase
    {
        private readonly int _catagoryId;

        public LastOpenDataControlViewModel(PlayDataInfo playDataInfo)
        {
            this.LastPlayDatas = playDataInfo.PlayDatas;
        }

        public LastOpenDataControlViewModel(int lotteryCatagoryId)
        {
            this._catagoryId = lotteryCatagoryId;
            this.OpenDatas = new ObservableCollection<OpenLotteryInfo>();
            this.Init();
        }

        private void Init()
        {
            ServiceClient instance = WCFServicesUtil<ServiceClient>.GetInstance(ServiceType.ServiceAPI);
            instance.GetLatestOpenLotteriesRecordsCompleted += delegate (object obj, GetLatestOpenLotteriesRecordsCompletedEventArgs arg) {
                foreach (OpenLotteryInfo info in arg.Result)
                {
                    this.OpenDatas.Add(info);
                }
            };
            instance.GetLatestOpenLotteriesRecordsAsync(this._catagoryId, 5);
        }

        public ObservableCollection<PlayData> LastPlayDatas { get; set; }

        public ObservableCollection<OpenLotteryInfo> OpenDatas { get; set; }
    }
}

